package com.sl.hx.shop.ui.mine.activity;

import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.sl.hx.shop.R;
import com.sl.hx.shop.base.BaseActivity;
import com.sl.hx.shop.base.BasePresenter;
import com.sl.hx.shop.constant.AppConfig;
import com.sl.hx.shop.http.ApiFactory;
import com.sl.hx.shop.http.HttpUtil;
import com.sl.hx.shop.http.ProgressSubscribe;
import com.sl.hx.shop.utils.SPUtils;
import com.sl.hx.shop.utils.ToastUtil;
import com.trello.rxlifecycle2.android.ActivityEvent;

import butterknife.BindView;
import butterknife.OnClick;
import io.reactivex.Observable;

public class FeedbackActivity extends BaseActivity {

    @BindView(R.id.et_idea)
    EditText etIdea;
    @BindView(R.id.et_phone)
    EditText etPhone;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_feedback;
    }

    @Override
    protected BasePresenter createPresenter() {
        return null;
    }

    @Override
    protected void initView() {
    }

    @Override
    protected void initData() {

    }

    @OnClick({R.id.iv_back, R.id.btn_submit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.btn_submit:
                feedBack();
                break;
        }
    }

    private void feedBack() {
        String editphone = etPhone.getText().toString().trim();
        String editIdea = etIdea.getText().toString().trim();
        if (TextUtils.isEmpty(editphone) || TextUtils.isEmpty(editIdea)) {
            ToastUtil.showShort(mContext, "输入内容不能为空");
        } else {
            Observable observable = ApiFactory.getInstance().feedBack(SPUtils.getInstance().getString(AppConfig.ID), editphone, editIdea);
            HttpUtil.getInstance().toSubscribe(observable, new ProgressSubscribe<String>(mContext) {
                @Override
                protected void _onNext(String s) {
                }

                @Override
                protected void _onError(String message) {
                }

                @Override
                public void onComplete() {
                    super.onComplete();
                    ToastUtil.showShort(mContext, "提交成功");
                }
            }, true, this, ActivityEvent.DESTROY);
        }
    }

}
